<?php
/*
 * Created on 18-sept.-2006
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 class AccueilController extends Zend_Controller_Action
 {
    public function indexAction()
    {
        if ( motion_isrunning() )
        {                        
            $db = Zend::registry('db');
            $session = Zend::registry('fSession');
            $acl = Zend::registry('acl');
            
            $sql = "SELECT * FROM threads";
            $mySelectThreads = $db->query($sql);
            $myThreads = $mySelectThreads->fetchAll();        
            
            $userAllowed = $acl->isAllowed($session->groupe, null, 'consult');

            $threads = array();
            foreach ($myThreads as $mythread)
            {
                $myThreadId = $mythread['id'];
                $myThreadName = $mythread['name'];
                $myThreadPath = threadPath($myThreadId);
                $myThreadStatus = threadStatus($myThreadId);
                
                $sql = "SELECT count(filename) FROM `security` WHERE `file_type` = '8' AND lu = 'N' AND `camera` = '" . $myThreadId . "'";
                $myCount = $db->fetchOne($sql);      
                
                array_push ($threads, array ("id"=>$myThreadId, "name"=>$myThreadName, "src"=>$myThreadPath, "status"=>$myThreadStatus, "count"=>$myCount));            
            }
          
            $View = Zend::registry('view');
            $View->myThreads = $threads;
            $View->userAllowed = $userAllowed;
            echo $View->render('accueilView.php');
        
        } else echo "Motion is not running !!!";
    }    
    public function noRouteAction()
    {
        $this->_redirect('/');
    }
}
?>
